/*
 * 文件名：DBHelper.java 版权：Copyright by www.sdhuijin.cn 描述： 修改人：Administrator 修改时间：2017年12月1日 修改内容：
 */

package cs;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class DBHelper
{
    public static final String url = "jdbc:mysql://127.0.0.1/mytest";

    public static final String name = "com.mysql.jdbc.Driver";

    public static final String user = "user";

    public static final String password = "123456";

    public Connection conn = null;

    public PreparedStatement pst = null;

    public DBHelper(String sql)
    {
        try
        {
            Class.forName(name);// 指定连接类
            conn = DriverManager.getConnection(url, user, password);// 获取连接
            pst = conn.prepareStatement(sql);// 准备执
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void close()
    {
        try
        {
            this.conn.close();
            this.pst.close();
        }
        catch (SQLException e)
        {}
    }

}